//
//  LFAccountOrderViewCell.m
//  LoveFruit
//
//  Created by 刘栋 on 16/9/24.
//  Copyright © 2016年 张令林. All rights reserved.
#import "LFAccountOrderViewCell.h"

@interface LFAccountOrderViewCell ()

@property (nonatomic,strong) NSArray *imageArray;

@property (nonatomic,strong) NSArray *butArray;

@end

@implementation LFAccountOrderViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self createUpUI];
    }
    return self;
}

- (void)createUpUI
{
    CGFloat margin = 8;
    
    //日期
    UILabel *dateLable = [UILabel labelWithText:@"2018-11-29" andTextColor:[UIColor blackColor] andFontSize:15];
    [self.contentView addSubview:dateLable];
    
    //时间
    UILabel *timeLable = [UILabel labelWithText:@"10:50:09" andTextColor:[UIColor blackColor] andFontSize:15];
    [self.contentView addSubview:timeLable];
    //状态
    UILabel *stateLable = [UILabel labelWithText:@"以完成" andTextColor:[UIColor redColor] andFontSize:15];
    [self.contentView addSubview:stateLable];
    stateLable.textColor = [UIColor redColor];
    //分割线
    UIImageView *lineView1 = [[UIImageView alloc] init];
    [self.contentView addSubview:lineView1];
    lineView1.backgroundColor = [UIColor lightGrayColor];
    
    UIImageView *lineView2 = [[UIImageView alloc] init];
    [self.contentView addSubview:lineView2];
    lineView2.backgroundColor = [UIColor lightGrayColor];
    
    UIImageView *lineView3 = [[UIImageView alloc] init];
    [self.contentView addSubview:lineView3];
    lineView3.backgroundColor = [UIColor lightGrayColor];
    
    //把图片添加到数组里面
    NSMutableArray *tempArray = [NSMutableArray array];
    //图片 创建5个view然后根据view的个数去隐藏或者显示
    for(int i=0;i<5;i++)
    {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"003"]];
        [self.contentView addSubview:iconView];
        
        iconView.backgroundColor = [UIColor randomColor];
        
        [tempArray addObject:iconView];
    }
    self.imageArray = tempArray;
    
    UIImageView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_go"]];
    [self.contentView addSubview:rightView];
    
    //商品的数量   和 价格
    
    UILabel *numberLable = [UILabel labelWithText:@"共7件商品" andTextColor:[UIColor colorWithHex:0x353d44] andFontSize:14];
    numberLable.textAlignment = NSTextAlignmentRight;
    
    [self.contentView addSubview:numberLable];
    
    
    UILabel *priceLable = [UILabel labelWithText:@"实付:￥42.2" andTextColor:[UIColor colorWithHex:0x353d44] andFontSize:14];
    priceLable.textAlignment = NSTextAlignmentRight;
    
    [self.contentView addSubview:priceLable];
    
    //去支付和再来一单
    NSMutableArray *teArray = [NSMutableArray array];
    for(int i=0;i<2;i++)
    {
        UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
        [but setTitle:@"再来一单" forState:UIControlStateNormal];
        
        [but setBackgroundImage:[UIImage imageNamed:@"v2_coupon_verify_normal"] forState:UIControlStateNormal];
        
        
        [but setTitleColor:[UIColor colorWithHex:0x353d44] forState:UIControlStateNormal];
        
        [but sizeToFit];
        
        //设置字体大小
        but.titleLabel.font = [UIFont systemFontOfSize:14];
        
        [self.contentView addSubview:but];
        [teArray addObject:but];
    }
    self.butArray = teArray;
    
    //设置约束
    [dateLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.offset(margin);
        make.top.offset(margin);
        
    }];
    
    //
    [timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(dateLable.mas_right).offset(margin);
        make.top.equalTo(dateLable.mas_top);
    }];
    
    //
    [stateLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.offset(-margin);
        make.top.equalTo(dateLable.mas_top);
        
    }];
    
    //一个像素的线
    CGFloat Xscale = 1 / [UIScreen mainScreen].scale ;
    
    //设置横线的约束
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(dateLable.mas_bottom).offset(margin);
        make.left.equalTo(dateLable.mas_left);
        make.right.offset(-margin);
        make.height.offset(Xscale);
        
    }];
    
    //设置图片约束
    [self.imageArray mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(dateLable.mas_bottom).offset(2*margin);
        make.width.offset(50);
        make.height.offset(50);
    }];
    
    for(int i=0;i<self.imageArray.count-1;i++)
    {
        UIImageView *currentImage = self.imageArray[i];
        UIImageView *nextImage = self.imageArray[i+1];
        if(i==0)
        {
           [currentImage mas_makeConstraints:^(MASConstraintMaker *make) {
              
               make.left.offset(margin);
               
           }];
        }
        [nextImage mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(currentImage.mas_right).offset(margin);
            
        }];
        
    }
    
    //第二条横线
    
    //获取数组第一个元素
    UIButton *firstBut = self.imageArray[0];
    
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.equalTo(lineView1);
        make.top.equalTo(firstBut.mas_bottom).offset(margin);
        make.height.offset(Xscale);
        
    }];
    
    //设置右边的指示器
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(firstBut);
        make.right.offset(-10);
        make.width.offset(10);
        make.height.offset(15);
        
    }];
    
    [priceLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(lineView2.mas_right);
        make.top.equalTo(lineView2.mas_bottom).offset(margin);
        //make.top.equalTo()
    }];
    
    //商品
    [numberLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(priceLable.mas_left).offset(-15);
        make.top.equalTo(priceLable.mas_top);
    }];
    
    //第三条横线
    [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.height.equalTo(lineView2);
        make.top.equalTo(priceLable.mas_bottom).offset(margin);
        
    }];
    
    //下面发福利
    
    [self.butArray mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.offset(70);
        make.height.offset(25);
        make.top.equalTo(lineView3.mas_bottom).offset(margin);
        
    }];
    
    for(int i=0;i<self.butArray.count-1;i++)
    {
        UIButton *currentbut = self.butArray[i];
        UIButton *nextBut = self.butArray[i+1];
        if(i==0)
        {
            [currentbut mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.offset(-margin);
                
            }];
        }
        if(i==self.butArray.count-2)
        {
            [nextBut mas_makeConstraints:^(MASConstraintMaker *make) {
               
                make.right.equalTo(currentbut.mas_left).offset(-margin);
                
            }];
        }
    }
}

@end
